﻿using Microsoft.EntityFrameworkCore;

namespace CodeFirst导航属性的使用示例.Models
{
    public class MyContext : DbContext
    {
        public MyContext(DbContextOptions options) : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

            base.OnModelCreating(modelBuilder);
            //设置一对多关系
            modelBuilder.Entity<Category>().HasData(new Category { Id = 1, Name = "手机" });
            modelBuilder.Entity<Category>().HasData(new Category { Id = 2, Name = "电脑" });
            modelBuilder.Entity<Category>().HasData(new Category { Id = 3, Name = "服装" });

            modelBuilder.Entity<Product>().HasData(new Product { Id = 1, Name = "华为手机", Price = 3999, CategoryId = 1 });
            modelBuilder.Entity<Product>().HasData(new Product { Id = 2, Name = "小米手机", Price = 2999, CategoryId = 1 });
            modelBuilder.Entity<Product>().HasData(new Product { Id = 3, Name = "苹果手机", Price = 5999, CategoryId = 1 });
            modelBuilder.Entity<Product>().HasData(new Product { Id = 4, Name = "联想电脑", Price = 4999, CategoryId = 2 });
            modelBuilder.Entity<Product>().HasData(new Product { Id = 5, Name = "戴尔电脑", Price = 3999, CategoryId = 2 });
            modelBuilder.Entity<Product>().HasData(new Product { Id = 6, Name = "华硕电脑", Price = 4999, CategoryId = 2 });
            modelBuilder.Entity<Product>().HasData(new Product { Id = 7, Name = "T恤", Price = 99, CategoryId = 3 });
            modelBuilder.Entity<Product>().HasData(new Product { Id = 8, Name = "牛仔裤", Price = 199, CategoryId = 3 });
            modelBuilder.Entity<Product>().HasData(new Product { Id = 9, Name = "连衣裙", Price = 299, CategoryId = 3 });



        }

       
        public DbSet<Category> Categories { get; set; }
        public DbSet<Product> Products { get; set; }


    }
}
